home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.2 / TIGA / demos / tigainit.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-01  |  3.4 KB  |  130 lines

  1. /* 
  2.     TIGA main module 
  3.     $Header: Devel:Tiga/TIGA_DEVEL/Allan/wb/RCS/tigamain.c,v 1.1 91/05/08 16:26:46 havemose Exp Locker: havemose $
  4.  
  5.     This module contains various small (and helpful) support routines.
  6.     Compile with -dTIGA_MAC if you don't want to use A2410.lib
  7. */
  8. #include <lattice/stdio.h>
  9. #include <a2410/typedefs.h>
  10. #include <a2410/devtiga.h>
  11. #include <a2410/ti_function_nums.h>
  12. #ifdef    TIGA_MAC
  13. #include <a2410/dev_macros.h>
  14. #else
  15. #include <clib/a2410_protos.h>
  16. #endif
  17. #include <lattice/math.h>
  18.  
  19. LONG TIGADATANAME[TIGA_DATA_SIZE];    /* data area for macros */
  20. struct IOExtTiga TIGAREQNAME;          /* TIGA IORequest for macros */
  21.  
  22. /* =================================================================================== */
  23.  
  24. BOOL    TIGA_Init(void)
  25. {
  26.     int    unit=0;
  27.     /* setup the IORequest */
  28.        TIGAREQNAME.tiga_Req.io_Message.mn_Node.ln_Succ    =    NULL;
  29.        TIGAREQNAME.tiga_Req.io_Message.mn_Node.ln_Pred    =    NULL;
  30.     TIGAREQNAME.tiga_Req.io_Message.mn_Node.ln_Type =     NT_MESSAGE;
  31.        TIGAREQNAME.tiga_Req.io_Message.mn_Node.ln_Pri    =    0;
  32.        TIGAREQNAME.tiga_Req.io_Message.mn_Node.ln_Name=NULL;
  33.        TIGAREQNAME.tiga_Req.io_Message.mn_Length=0;
  34.        TIGAREQNAME.tiga_Req.io_Device=NULL;
  35.        TIGAREQNAME.tiga_Req.io_Unit=NULL;
  36.        TIGAREQNAME.tiga_Req.io_Command=CMD_INVALID;
  37.        TIGAREQNAME.tiga_Req.io_Flags=0;
  38.        TIGAREQNAME.tiga_Req.io_Error=0;
  39.        TIGAREQNAME.tiga_Req.io_Actual=0;
  40.        TIGAREQNAME.tiga_Req.io_Length=-1;
  41.        TIGAREQNAME.tiga_Req.io_Data=(APTR)TIGADATANAME;
  42.        TIGAREQNAME.tiga_Req.io_Offset=0;
  43.        TIGAREQNAME.tiga_Return=0;
  44.  
  45.     TIGAREQNAME.tiga_Req.io_Message.mn_ReplyPort = (struct Port *)CreatePort(NULL,0);
  46.     if (TIGAREQNAME.tiga_Req.io_Message.mn_ReplyPort == NULL)
  47.      {
  48.         printf("Can't create the reply port\n");
  49.         return FALSE;
  50.       }
  51.  
  52.     /* open the device */
  53.     if ((OpenDevice(TIGADEVICENAME,unit,&TIGAREQNAME,LOCK_UNIT)) != NULL)
  54.      {
  55.         printf("can't open a2410 device\n");
  56.         DeletePort(TIGAREQNAME.tiga_Req.io_Message.mn_ReplyPort);
  57.         return FALSE;
  58.      }
  59.  
  60.     /* get TIGA going */
  61.     if  (!set_videomode(TIGA, CLR_SCREEN|INIT))
  62.      {
  63.         printf("FATAL ERROR - unable to initialize TIGA ...\n");
  64.         CloseDevice(&TIGAREQNAME);
  65.         DeletePort(TIGAREQNAME.tiga_Req.io_Message.mn_ReplyPort);
  66.         return FALSE;
  67.      }
  68.     return TRUE;
  69. }
  70. /* -------------------------------------------------------------------------------- */
  71.  
  72. void    TIGA_Close(void)
  73. {
  74.     CloseDevice(&TIGAREQNAME);
  75.     DeletePort(TIGAREQNAME.tiga_Req.io_Message.mn_ReplyPort);
  76.     TIGAREQNAME.tiga_Req.io_Message.mn_ReplyPort = NULL;
  77. }
  78. /* -------------------------------------------------------------------------------- */
  79. void    TIGA_Break(void)
  80. {
  81.     TIGA_Close();
  82.     exit(0);
  83. }
  84. /* -------------------------------------------------------------------------------- */
  85. void    TIGA_SetRandPalet(void)
  86. {
  87.     int    i;
  88.     CONFIG    config;
  89.  
  90.     get_config(&config);
  91.     if(function_implemented(SET_PALET_ENTRY))
  92.     {
  93.       for (i=1; i<config.mode.palet_size; i++)
  94.        {
  95.         set_palet_entry(i, rand() & 0xff,
  96.                      rand() & 0xff,
  97.                    rand() & 0xff,
  98.                    rand() & 0xff);
  99.        }
  100.     }
  101. }
  102. /* -------------------------------------------------------------------------------- */
  103.  
  104. #if 0
  105.  
  106. Typical TIGA application struture:
  107.  
  108. void main(int argc, char **argv)
  109. {
  110.     if (TIGA_Init())
  111.      {
  112.             YourFunction();
  113.         TIGA_Close();
  114.      }
  115. }
  116.  
  117. or if you want to install CTRL-C break
  118.  
  119. void main(int argc, char **argv)
  120. {
  121.     if (TIGA_Init())
  122.      {
  123.         onbreak(TIGA_Break);
  124.             YourFunction();    /* check for CTRL-C by using chkabort() */
  125.         TIGA_Close();
  126.      }
  127. }
  128.  
  129. #endif
  130.